package com.zoe.onelink.governance.property;

import com.alibaba.nacos.api.config.ConfigType;
import com.zoe.onelink.governance.gateway.model.SmartGatewayRoute;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-10-20
 */
@Data
@ConfigurationProperties(prefix = "onelink.governance")
public class OnelinkGovernanceProperties {

    private Gateway gateway = new Gateway();

    @Data
    public static class Gateway {

        private DynamicRoutePublish dynamicRoutePublish = new DynamicRoutePublish();


        @Data
        public static class DynamicRoutePublish {

            public static final String CONFIG_DATA_ID = "gateway-routes-dynamic";

            public static final String CONFIG_GROUP_NAME = "DYNAMIC_GEN";

            /**
             * 开启动态网关路由发布
             */
            private boolean enabled = true;

            /**
             * 配置前缀
             */
            private String prefix = "spring.cloud.gateway.onelink";

            /**
             * 配置ID
             */
            private String configDataId = CONFIG_DATA_ID;

            /**
             * 配置分组名
             */
            private String configGroupName = CONFIG_GROUP_NAME;

            /**
             * 配置类型 (默认YAML格式)
             */
            private ConfigType configType = ConfigType.YAML;

            /**
             * 安全路由模式 (默认开启: 禁止'/**'等危险通配符)
             */
            private boolean safetyMode = true;

            /**
             * 异步推送路由
             */
            private boolean async = true;

            /**
             * 发布失败重试次数 (默认3次)
             */
            private int maxRetryOnFailure = 3;

            /**
             * 发布失败等待多久再次重试 (默认3秒)
             */
            private Duration retryOnFailureWaitTime = Duration.ofSeconds(3);

            /**
             * 路由列表
             */
            private List<SmartGatewayRoute> routes = new ArrayList<>();

            /**
             * todo: 有需要再支持
             * true: 不同服务的配置合并到同一个文件中存储 (默认开启)
             * false: 根据服务名为每一个服务都创建一个路由配置文件
             */
            private boolean storedMerge = true;
        }

    }


}
